package thread.state;

public class WaitThreadStateTest {
    public static void main(String[] args) {
        final Object object = new Object();

        Thread waitThread = new Thread() {
            @Override
            public void run() {
                super.run();

                try {
                    waitTest();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            private void waitTest() throws InterruptedException {
                synchronized (object) {
                    object.wait();
                    System.out.println("After wait the thread state is " + getState().name());
                }

                System.out.println("After wait the thread state is " + getState().name());

                for (; ; ) {
                    // do nothing
                }
            }
        };

        waitThread.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("After wait() the thread state is " + waitThread.getState().name());

        synchronized (object) {
            object.notify();
        }

        System.out.println("After notify() the thread state is " + waitThread.getState().name());
    }
}